package com.wang.controller;


import com.wang.enums.BizCodeEnum;
import com.wang.request.LockCouponRecordsRequest;
import com.wang.request.NewUserCouponRequest;
import com.wang.service.CouponRecordService;
import com.wang.util.JsonData;
import com.wang.vo.CouponRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 落日孤城
 * @since 2025-05-10
 */
@Api("优惠券领取记录模块")
@RestController
@RequestMapping("/api/coupon_record/v1")
public class CouponRecordController {
    @Autowired
    private CouponRecordService couponRecordService;


    @ApiOperation("分页查询优惠券领取记录")
    @GetMapping("/page")
    public JsonData page(
            @ApiParam("当前页")
            @RequestParam(value = "page",defaultValue = "1")
            Integer page,

            @ApiParam("每页显示多少条")
            @RequestParam(value = "size",defaultValue = "10")
            Integer size
    ){
        Map<String, Object> map = couponRecordService.page(page, size);
        return JsonData.buildSuccess(map);
    }


    @ApiOperation("根据优惠券id查询领取记录")
    @GetMapping("/detail/{record_id}")
    public JsonData detail(
            @ApiParam("领取记录id")
            @PathVariable("record_id")
            Integer recordId
    ){
        CouponRecordVO couponRecordVO = couponRecordService.findById(recordId);
        return couponRecordVO == null
                ? JsonData.buildResult(BizCodeEnum.COUPON_NO_EXITS)
                : JsonData.buildSuccess(couponRecordVO);
    }


    @ApiOperation("rpc-锁定优惠券记录")
    @PostMapping("/lock_records")
    public JsonData rockRecord(
            @ApiParam("锁定优惠券记录对象")
            @RequestBody
            LockCouponRecordsRequest  lockCouponRecordsRequest
    ){
        return couponRecordService.lockCouponRecords(lockCouponRecordsRequest);
    }
    
}

